home *** CD-ROM | disk | FTP | other *** search
/ World of Video / World of Video.iso / gfxprograms / 3dprograms / rayshade-4.0 / unapplied / mmaloc.patch < prev    next >
Internet Message Format  |  1995-02-13  |  14KB

  1. From theseas!fs.Princeton.EDU!cek Sat, 6 Feb 93 01:37:22 EET
  2. Received: by kriton.UUCP (V1.16/Amiga)
  3.     id AA00000; Sat, 6 Feb 93 01:37:22 EET
  4. Received: by theseas.ntua.gr with UUCP; Wed, 3 Feb 93 02:32:14 +0200
  5. Received: from mcsun.EU.net by pythia.ics.forth.gr via ITEnet with SMTP;
  6.     id AA00647 (5.65c/FORTH-ICS-3.0-MHS-7.0); Wed, 3 Feb 1993 02:26:47 +0200
  7. Received: by mcsun.EU.net via EUnet
  8.     id AA27047 (5.65b/CWI-2.205); Wed, 3 Feb 1993 01:24:36 +0100
  9. Received: from Princeton.EDU by relay2.UU.NET with SMTP 
  10.     (5.61/UUNET-internet-primary) id AA23214; Tue, 2 Feb 93 19:22:40 -0500
  11. Received: from fs.Princeton.EDU by Princeton.EDU (5.65b/2.95/princeton)
  12.     id AA03959; Tue, 2 Feb 93 18:18:11 -0500
  13. Received: by fs.Princeton.EDU (4.1/1.105)
  14.     id AA21112; Tue, 2 Feb 93 18:18:07 EST
  15. Received: from fsa.cpsc.ucalgary.ca by fs.Princeton.EDU (4.1/1.105)
  16.     id AA21011; Tue, 2 Feb 93 18:17:05 EST
  17. Received: from do.cpsc.ucalgary.ca by fsa.cpsc.ucalgary.ca (4.1/CSd1.2)
  18.     id AA01083; Tue, 2 Feb 93 15:23:03 MST
  19. Received: by do.cpsc.ucalgary.ca (4.1/cs1.0)
  20.     id AA23391; Tue, 2 Feb 93 15:23:07 MST
  21. Date: Tue, 2 Feb 93 15:23:03 MST
  22. Message-Id: <9302022223.AA01083@fsa.cpsc.ucalgary.ca>
  23. Errors-To: Princeton.EDU!cek
  24. Remailed-Date: Tue Feb  2 18:17:30 EST 1993
  25. From: cpsc.ucalgary.ca!jamesm (Mark James)
  26. To: cs.Princeton.EDU!rayshade-users
  27. Subject: Gnu mmalloc and rayshade
  28.  
  29. A few of the people in our department are raytracing some fairly
  30. large scenes with rayshade.  For example, a friend of mine has
  31. modeled a field of grass which gives him an 80MB input file. :)  One
  32. problem with this is that rayshade fairly quickly runs out of memory.
  33. :)  However, there is a way around this.  GDB 4.7 has a library
  34. called mmalloc which uses mmap for allocating memory rather than
  35. sbrk.  So now all you need to do is specify the name of a swap file
  36. on a big disk, and rayshade can chew up all the memory it needs.
  37. It's not wonderfully fast, but what can you expect with an 80MB input
  38. file, and at least it gets the job done. :)
  39.  
  40. I've patched rayshade.4.0.6 to use mmalloc.  The patch isn't pretty,
  41. and it doesn't change the Configure script which it really should,
  42. but here it is anyhow.  When Configure asks for C flags, add
  43. "-DMMALLOC", and specify the libmmalloc library when it asks you
  44. about libraries. Please let me know if you have problems with it, or
  45. find it useful.
  46.  
  47.      M.
  48.  
  49. use: patch -p0 -d rayshade.4.0 < mmalloc-patch
  50.  
  51. *** ./libray/libcommon/expr.c    Sun Feb  9 20:04:04 1992
  52. --- ../mrayshade/./libray/libcommon/expr.c    Tue Feb  2 10:47:10 1993
  53. ***************
  54. *** 289,295 ****
  55.   {
  56.       if (!expr->symtab) {
  57.           if (expr->type == BUILTIN_EXPR && expr->params)
  58. !             free((voidstar)expr->params);
  59. !         free((voidstar)expr);
  60.       }
  61.   }
  62. --- 289,295 ----
  63.   {
  64.       if (!expr->symtab) {
  65.           if (expr->type == BUILTIN_EXPR && expr->params)
  66. !             Free((voidstar)expr->params);
  67. !         Free((voidstar)expr);
  68.       }
  69.   }
  70. *** ./libray/libcommon/memory.c    Sun Feb  9 20:03:29 1992
  71. --- ../mrayshade/./libray/libcommon/memory.c    Tue Feb  2 10:47:10 1993
  72. ***************
  73. *** 24,31 ****
  74. --- 24,33 ----
  75.   #include <memory.h>
  76.   #endif
  77.   #include "common.h"
  78. + #include "../../libshade/options.h"
  79.   
  80.   unsigned long TotalAllocated;
  81. + unsigned long TotalDeallocated;
  82.   
  83.   voidstar
  84.   Malloc(bytes)
  85. ***************
  86. *** 33,41 ****
  87.   {
  88.       voidstar res;
  89.   
  90. !     TotalAllocated += bytes;
  91.       res = (voidstar)malloc(bytes);
  92.       if (res == (voidstar)NULL)
  93.           RLerror(RL_PANIC,
  94.               "Out of memory trying to allocate %d bytes.\n",bytes);
  95. --- 35,45 ----
  96.   {
  97.       voidstar res;
  98.   
  99. ! #ifdef MMALLOC
  100. !     res = (voidstar)mmalloc(Options.mmallocd,bytes);
  101. ! #else
  102.       res = (voidstar)malloc(bytes);
  103. + #endif
  104.       if (res == (voidstar)NULL)
  105.           RLerror(RL_PANIC,
  106.               "Out of memory trying to allocate %d bytes.\n",bytes);
  107. ***************
  108. *** 51,56 ****
  109. --- 55,71 ----
  110.       res = Malloc(nelem*elen);
  111.       bzero(res, (int)nelem*elen);
  112.       return res;
  113. + }
  114. + void
  115. + Free(pointer)
  116. + voidstar pointer;
  117. + {
  118. + #ifdef MMALLOC
  119. +         mfree(Options.mmallocd,pointer);
  120. + #else
  121. +     free(pointer);
  122. + #endif
  123.   }
  124.   
  125.   void
  126. *** ./libray/libcommon/transform.c    Sun Feb  9 20:04:12 1992
  127. --- ../mrayshade/./libray/libcommon/transform.c    Tue Feb  2 10:47:12 1993
  128. ***************
  129. *** 57,64 ****
  130.   Trans *trans;
  131.   {
  132.       if (trans->tr)
  133. !         free((voidstar)trans->tr);
  134. !     free((voidstar)trans);
  135.   }
  136.   
  137.   void
  138. --- 57,64 ----
  139.   Trans *trans;
  140.   {
  141.       if (trans->tr)
  142. !         Free((voidstar)trans->tr);
  143. !     Free((voidstar)trans);
  144.   }
  145.   
  146.   void
  147. *** ./libray/libobj/blob.c    Sun Feb  9 20:04:19 1992
  148. --- ../mrayshade/./libray/libobj/blob.c    Tue Feb  2 10:47:21 1993
  149. ***************
  150. *** 131,137 ****
  151.           blob->list[i].y = cur->mvec.y;
  152.           blob->list[i].z = cur->mvec.z;
  153.           mlist = mlist->next;
  154. !         free((voidstar)cur);
  155.       }
  156.       /* 
  157.        * Allocate room for Intersection Structures and
  158. --- 131,137 ----
  159.           blob->list[i].y = cur->mvec.y;
  160.           blob->list[i].z = cur->mvec.z;
  161.           mlist = mlist->next;
  162. !         Free((voidstar)cur);
  163.       }
  164.       /* 
  165.        * Allocate room for Intersection Structures and
  166. *** ./libray/libobj/geom.c    Sun Feb  9 20:04:11 1992
  167. --- ../mrayshade/./libray/libobj/geom.c    Tue Feb  2 10:47:22 1993
  168. ***************
  169. *** 306,312 ****
  170.       GeomList *ltmp;
  171.   
  172.       ltmp = list->next;    /* Save new head. */
  173. !     free((voidstar)list);    /* Free old head. */
  174.       return ltmp;        /* Return new head. */
  175.   }
  176.   
  177. --- 306,312 ----
  178.       GeomList *ltmp;
  179.   
  180.       ltmp = list->next;    /* Save new head. */
  181. !     Free((voidstar)list);    /* Free old head. */
  182.       return ltmp;        /* Return new head. */
  183.   }
  184.   
  185. *** ./libray/libobj/grid.c    Sun Feb  9 20:04:13 1992
  186. --- ../mrayshade/./libray/libobj/grid.c    Tue Feb  2 10:47:22 1993
  187. ***************
  188. *** 396,402 ****
  189.               for (z = 0; z < grid->zsize; z++) {
  190.                   for (cell = grid->cells[x][y][z]; cell; cell = next) {
  191.                       next = cell->next;
  192. !                     free((voidstar)cell);
  193.                   }
  194.                   grid->cells[x][y][z] = (GeomList *)NULL;
  195.               }
  196. --- 396,402 ----
  197.               for (z = 0; z < grid->zsize; z++) {
  198.                   for (cell = grid->cells[x][y][z]; cell; cell = next) {
  199.                       next = cell->next;
  200. !                     Free((voidstar)cell);
  201.                   }
  202.                   grid->cells[x][y][z] = (GeomList *)NULL;
  203.               }
  204. *** ./libray/libobj/hf.c    Sun Feb  9 20:04:18 1992
  205. --- ../mrayshade/./libray/libobj/hf.c    Tue Feb  2 10:47:22 1993
  206. ***************
  207. *** 210,217 ****
  208.           hitpos.x = ray->pos.x + ray->dir.x * offset;
  209.           hitpos.y = ray->pos.y + ray->dir.y * offset;
  210.           hitpos.z = ray->pos.z + ray->dir.z * offset;
  211. !     } else
  212. !         hitpos = ray->pos;
  213.       /*
  214.        * Find out in which cell "hitpoint" is.
  215.        */
  216. --- 210,216 ----
  217.           hitpos.x = ray->pos.x + ray->dir.x * offset;
  218.           hitpos.y = ray->pos.y + ray->dir.y * offset;
  219.           hitpos.z = ray->pos.z + ray->dir.z * offset;
  220. !     }
  221.       /*
  222.        * Find out in which cell "hitpoint" is.
  223.        */
  224. ***************
  225. *** 509,514 ****
  226. --- 508,515 ----
  227.       tmp2.y = tri->v3.y - tri->v1.y;
  228.       tmp2.z = tri->v3.z - tri->v1.z;
  229.   
  230. +         VecScale(hf->size, tmp1, &tmp1);
  231. +         VecScale(hf->size, tmp2, &tmp2);
  232.       (void)VecNormCross(&tmp1, &tmp2, &tri->norm);
  233.   
  234.       tri->d = -dotp(&tri->v1, &tri->norm);
  235. ***************
  236. *** 657,663 ****
  237.   hfTri *tri;
  238.   {
  239.       if (hf->q[hf->qtail])        /* Free old triangle data */
  240. !         free((voidstar)hf->q[hf->qtail]);
  241.       hf->q[hf->qtail] = tri;        /* Put on tail */
  242.       hf->qtail = (hf->qtail + 1) % hf->qsize;    /* Increment tail */
  243.   }
  244. --- 658,664 ----
  245.   hfTri *tri;
  246.   {
  247.       if (hf->q[hf->qtail])        /* Free old triangle data */
  248. !         Free((voidstar)hf->q[hf->qtail]);
  249.       hf->q[hf->qtail] = tri;        /* Put on tail */
  250.       hf->qtail = (hf->qtail + 1) % hf->qsize;    /* Increment tail */
  251.   }
  252. *** ./libray/libobj/poly.c    Sun Feb  9 20:04:08 1992
  253. --- ../mrayshade/./libray/libobj/poly.c    Tue Feb  2 10:47:22 1993
  254. ***************
  255. *** 67,73 ****
  256.       for(curp = plist; curp != (PointList *)0; curp = pltmp) {
  257.           poly->points[i--] = curp->vec;
  258.           pltmp = curp->next;
  259. !         free((voidstar)curp);
  260.       }
  261.   
  262.       /*
  263. --- 67,73 ----
  264.       for(curp = plist; curp != (PointList *)0; curp = pltmp) {
  265.           poly->points[i--] = curp->vec;
  266.           pltmp = curp->next;
  267. !         Free((voidstar)curp);
  268.       }
  269.   
  270.       /*
  271. ***************
  272. *** 86,92 ****
  273.            * Degenerate normal --> degenerate polygon
  274.            */
  275.           RLerror(RL_WARN, "Degenerate polygon.\n");
  276. !         free((voidstar)poly->points);
  277.           return (Polygon *)NULL;
  278.       }
  279.   
  280. --- 86,92 ----
  281.            * Degenerate normal --> degenerate polygon
  282.            */
  283.           RLerror(RL_WARN, "Degenerate polygon.\n");
  284. !         Free((voidstar)poly->points);
  285.           return (Polygon *)NULL;
  286.       }
  287.   
  288. *** ./libray/libsurf/surface.c    Sun Feb  9 20:03:52 1992
  289. --- ../mrayshade/./libray/libsurf/surface.c    Tue Feb  2 10:47:26 1993
  290. ***************
  291. *** 135,141 ****
  292.   {
  293.       SurfList *stmp = list->next;
  294.   
  295. !     free((voidstar)list);
  296.       return stmp;
  297.   }
  298.   
  299. --- 135,141 ----
  300.   {
  301.       SurfList *stmp = list->next;
  302.   
  303. !     Free((voidstar)list);
  304.       return stmp;
  305.   }
  306.   
  307. *** ./libshade/funcdefs.h    Sun Feb  9 20:03:18 1992
  308. --- ../mrayshade/./libshade/funcdefs.h    Tue Feb  2 10:47:33 1993
  309. ***************
  310. *** 36,42 ****
  311.    * Misc. routines.
  312.    */
  313.   #ifndef I_STDLIB
  314. ! extern void    free(), exit();
  315.   #endif
  316.   
  317.   extern void get_cpu_time(), read_input_file();
  318. --- 36,42 ----
  319.    * Misc. routines.
  320.    */
  321.   #ifndef I_STDLIB
  322. ! extern void    Free(), exit();
  323.   #endif
  324.   
  325.   extern void get_cpu_time(), read_input_file();
  326. *** ./libshade/misc.c    Sun Feb  9 20:03:59 1992
  327. --- ../mrayshade/./libshade/misc.c    Tue Feb  2 10:47:33 1993
  328. ***************
  329. *** 37,42 ****
  330. --- 37,46 ----
  331.   #include "options.h"
  332.   #include "stats.h"
  333.   
  334. + #ifdef MMALLOC
  335. + #include <fcntl.h>
  336. + #endif
  337.   Float RSabstmp;    /* Temporary value used by fabs macro.  Ugly. */
  338.   static void RSmessage();
  339.   
  340. ***************
  341. *** 103,108 ****
  342. --- 107,135 ----
  343.               "Cannot open stats file %s.\n", Options.statsname);
  344.       }
  345.   }
  346. + #ifdef MMALLOC
  347. + void
  348. + InitMMalloc()
  349. + {
  350. +     int fd;
  351. +     if (Options.mmapname == (char *)NULL)
  352. +         return;        /* Not specified or already opened. */
  353. +     fd = open(Options.mmapname, (O_CREAT | O_RDWR), 0600);
  354. +     unlink(Options.mmapname);
  355. +     if (fd < 0) {
  356. +         RLerror(RL_PANIC,
  357. +             "Cannot open mmalloc file %s.\n", Options.statsname);
  358. +     }
  359. +     Options.mmallocd=(voidstar)mmalloc_attach(fd,0xE0000000);  /* 0xE... is a hack from GDB 4.7  */
  360. +     if(Options.mmallocd==0){
  361. +         RLerror(RL_PANIC,
  362. +             "Mmalloc_attatch failed!\n");
  363. +     }
  364. +     
  365. + }
  366. + #endif
  367.   
  368.   void
  369.   RLerror(level, pat, arg1, arg2, arg3)
  370. *** ./libshade/options.c    Sun Feb  9 20:04:09 1992
  371. --- ../mrayshade/./libshade/options.c    Tue Feb  2 10:47:33 1993
  372. ***************
  373. *** 137,142 ****
  374. --- 137,157 ----
  375.                   Options.samplemap = !Options.samplemap;
  376.                   break;
  377.   #endif
  378. + #ifdef MMALLOC
  379. +             case 'M':
  380. +                 if (argv[1][0] == '-') {
  381. +                     /* User probably blew it, and
  382. +                      * it's difficult to remove a file
  383. +                      * that begins with '-'...
  384. +                      */
  385. +                     usage();
  386. +                     exit(2);
  387. +                 }
  388. +                 Options.mmapname = strsave(argv[1]);
  389. +                 InitMMalloc();
  390. +                 argv++; argc--;
  391. +                 break;
  392. + #endif                
  393.               case 'N':
  394.                   Options.totalframes = atof(argv[1]);
  395.                   Options.totalframes_set = TRUE;
  396. ***************
  397. *** 317,322 ****
  398. --- 332,340 ----
  399.       fprintf(stderr,"\t-l \t\t(Render image for left eye view.)\n");
  400.   #ifdef URT
  401.       fprintf(stderr,"\t-m \t\t(Output sample map in alpha channel.)\n");
  402. + #endif
  403. + #ifdef MMALLOC
  404. +     fprintf(stderr,"\t-M filename \t(Use filename for swapping.)\n");
  405.   #endif
  406.       fprintf(stderr,"\t-N number\t(Render given number of frames.)\n");
  407.       fprintf(stderr,"\t-n \t\t(Do not render shadows.)\n");
  408. *** ./libshade/options.h    Sun Feb  9 20:03:53 1992
  409. --- ../mrayshade/./libshade/options.h    Tue Feb  2 10:47:33 1993
  410. ***************
  411. *** 74,79 ****
  412. --- 74,83 ----
  413.       int    alpha;            /* Write alpha channel? */
  414.       int    exp_output;        /* Write exponential RLE file? */
  415.   #endif
  416. + #ifdef MMALLOC
  417. +     char * mmapname;
  418. +     void * mmallocd;
  419. + #endif
  420.       Float    eyesep,            /* Eye separation (for Stereo mode) */
  421.           gamma,            /* Gamma value (0 == no correction) */
  422.           starttime,        /* Think about it ... */
  423. *** ./libshade/shade.c    Sun Feb  9 20:04:12 1992
  424. --- ../mrayshade/./libshade/shade.c    Tue Feb  2 10:47:34 1993
  425. ***************
  426. *** 343,349 ****
  427.           ColorAdd(*color, newcol, color);
  428.           /* Free pushed medium */
  429.           if (enter)
  430. !             free((voidstar)NewRay.media);
  431.       }
  432.   
  433.       return total_int_refl;
  434. --- 343,349 ----
  435.           ColorAdd(*color, newcol, color);
  436.           /* Free pushed medium */
  437.           if (enter)
  438. !             Free((voidstar)NewRay.media);
  439.       }
  440.   
  441.       return total_int_refl;
  442. *** ./libshade/yacc.y    Sun Feb  9 20:04:21 1992
  443. --- ../mrayshade/./libshade/yacc.y    Tue Feb  2 10:47:35 1993
  444. ***************
  445. *** 537,543 ****
  446.                * Eye can be transformed...
  447.               if (CurMatrix) {
  448.                   PointTransform(&Camera.pos, CurMatrix);
  449. !                 free((voidstar)CurMatrix);
  450.                   CurMatrix = (Matrix*)NULL;
  451.               }
  452.                */
  453. --- 537,543 ----
  454.                * Eye can be transformed...
  455.               if (CurMatrix) {
  456.                   PointTransform(&Camera.pos, CurMatrix);
  457. !                 Free((voidstar)CurMatrix);
  458.                   CurMatrix = (Matrix*)NULL;
  459.               }
  460.                */
  461. ***************
  462. *** 806,812 ****
  463.                * converted from 3.0, surfnames this can account
  464.                * for lots o' bytes.
  465.                */
  466. !             free((voidstar)$1);
  467.           }
  468.           | tCURSURF
  469.           {
  470. --- 806,812 ----
  471.                * converted from 3.0, surfnames this can account
  472.                * for lots o' bytes.
  473.                */
  474. !             Free((voidstar)$1);
  475.           }
  476.           | tCURSURF
  477.           {
  478. *** ./raypaint/render.c    Sun Feb  9 20:04:20 1992
  479. --- ../mrayshade/./raypaint/render.c    Tue Feb  2 10:47:40 1993
  480. ***************
  481. *** 232,238 ****
  482.           PictureWriteLine(pixelbuf);
  483.       }
  484.       PictureEnd();
  485. !     free((voidstar)pixelbuf);
  486.   }
  487.   
  488.   Float
  489. --- 232,238 ----
  490.           PictureWriteLine(pixelbuf);
  491.       }
  492.       PictureEnd();
  493. !     Free((voidstar)pixelbuf);
  494.   }
  495.   
  496.   Float
  497. *** ./rayview/spheregen.c    Sun Feb  9 20:04:07 1992
  498. --- ../mrayshade/./rayview/spheregen.c    Tue Feb  2 10:47:42 1993
  499. ***************
  500. *** 204,211 ****
  501.       }
  502.   
  503.       if (level > 1) {
  504. !         free(old->poly);
  505. !         free(old);
  506.       }
  507.   
  508.       /* Continue subdividing new triangles */
  509. --- 204,211 ----
  510.       }
  511.   
  512.       if (level > 1) {
  513. !         Free(old->poly);
  514. !         Free(old);
  515.       }
  516.   
  517.       /* Continue subdividing new triangles */
  518.  
  519. ----------
  520. Administrivia: rayshade-request@cs.princeton.edu
  521. Mailing list: rayshade-users@cs.princeton.edu
  522.  
  523.